package com.tepth.busfix.main.repair;

import com.tepth.busfix.bean.reponse.Process;
import com.tepth.busfix.bean.reponse.Repair;
import com.tepth.busfix.network.ApiModel;
import com.tepth.busfix.network.Network;

import java.util.List;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by TMVPHelper on 2017/03/15
 */
public class RepairModel implements RepairContract.Model {

    @Override
    public Observable<ApiModel<Repair>> getRepair(String authKey, long id) {
        return Network.getApiService().repairInfo(authKey, id)
                .subscribeOn(Schedulers.io())
                .map(new Function<ApiModel<Repair>, ApiModel<Repair>>() {
                    @Override
                    public ApiModel<Repair> apply(ApiModel<Repair> repairApiModel) throws Exception {
                        return null;
                    }
                })
                .observeOn(AndroidSchedulers.mainThread());
    }

    @Override
    public Observable<ApiModel<String>> postRepair(String authKey, String info) {
        return Network.getApiService().startRepair(authKey, info)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

    @Override
    public Observable<ApiModel<List<Process>>> getProcess(String authKey, long troubleTypeId,
                                                          String troubleName) {
        return Network.getApiService().getProcessBytrouble(authKey, troubleTypeId,troubleName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

    @Override
    public Observable<ApiModel<String>> cancelPunchCard(String key, String json) {
        return Network.getApiService().cancelPunchCard(key, json)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }
}